package cn.hanyx.coder.design.pattern.structural.composite.demo01;

import java.util.ArrayList;
import java.util.List;

/**
 * Department
 *
 * @author hanyx
 * @date 2020/08/21
 */
public class Department extends HumanResource {

    private List<HumanResource> subNode = new ArrayList<>();

    public Department(long id) {
        super(id);
    }

    @Override
    public double calculateSalary() {
        double totalSalary = 0;
        for (HumanResource hr : subNode) {
            totalSalary += hr.calculateSalary();
        }
        this.salary = totalSalary;
        return totalSalary;
    }

    public void addSubNode(HumanResource humanResource) {
        subNode.add(humanResource);
    }

    @Override
    public String toString() {
        return "Department{" +
                "id=" + id +
                ", salary=" + salary +
                '}';
    }
}
